package com.xiangxiangjd.serviceImpl;

import com.xiangxiangjd.controller.helper.$;
import com.xiangxiangjd.bean.ManagementGoods;
import com.xiangxiangjd.mapper.ManagementGoodsMapper;
import com.xiangxiangjd.service.ManagementGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiangxiangjd.bean.result.ResultPage;
import com.xiangxiangjd.controller.model.ApiResultModel;

import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <p>
    * 处置的物品 服务实现类
    * </p>
*
* @author 肖守凯
* @since 2021-11-23
*/
@Service
public class ManagementGoodsServiceImpl extends ServiceImpl<ManagementGoodsMapper, ManagementGoods> implements ManagementGoodsService {
    /** 添加ManagementGoods
    * @param managementGoods  前端传进的参数
    * @return 返回统一信息
    */
    @Override
    public ApiResultModel addManagementGoods(ManagementGoods managementGoods  ) {
    if(this.save(managementGoods )){
    return $.success();
    }else{
    return $.error("添加失败");
    }
    }
    /** 编辑跳转页面的回显数据ManagementGoods
    * @param id  前端传进的参数
    * @return 返回实体类
    */
    @Override
    public ManagementGoods selectManagementGoodsByIdManagementGoods(String id ){
    return this.getById(id);
    }


    /** 编辑ManagementGoods
    * @param managementGoods  前端传进的参数
    * @return 返回统一信息
    */
    @Override
    public ApiResultModel editManagementGoods(ManagementGoods managementGoods  ) {
    if(this.updateById(managementGoods )){
    return $.success();
    }else{
    return $.error("编辑失败");
    }
    }
    /** 删除一条ManagementGoods
    * @param ids  前端传进的ID
    * @return 返回统一信息
    */
    @Override
    public   ApiResultModel delManagementGoodss(List ids){

    int i = baseMapper.deleteBatchIds(ids);

    return $.success(i);

    }

    /** 分页查询ManagementGoods
    * @param page  页码
    * @param limit  查几条
    * @param managementGoods  前端传进的参数
    * @return 返回统一分页信息
    */
    @Override
    public  ResultPage findManagementGoodsByPage(Integer page, Integer limit,ManagementGoods managementGoods){
    Map<String , Object> paramMap = new HashMap<>();
    page= page==null?1:page;
    limit= limit==null?20:limit;


        paramMap.put("page", (page - 1) * limit);
        paramMap.put("limit", limit);
        paramMap.put("managementGoods", managementGoods);
        List<ManagementGoods> list = baseMapper.selectMyPage(paramMap);
        Integer count = baseMapper.countMyPage(paramMap);
        ResultPage<ManagementGoods> resultPage = new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(count);
        resultPage.setMsg("成功");
        resultPage.setData(list);
        return resultPage;
        }
    }
